window.workspace = function(){
	var response  = <?#$respons?>;
	var store, sm, grid, sid={'name':Ext.id(), 'status':Ext.id()};
	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/workflow/apply/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
            field		: 'id',
            direction	: 'DESC'
		},
		baseParams	: {
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'name', 'details', 'status', 'class', 'remark']
	});
	sm   = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
 	grid = {
		xtype		: 'grid',
		title		: response.title,
	    store		: store,
		region		: 'center', 
	    columns		: [
	    	sm,
			{header: 'ID编号',width:80,sortable:true,dataIndex:'id'},
			{header: '流程名称', width:140, dataIndex:'name'},
			{header: '流程业务处理类', width:120, dataIndex:'details'},
			{header: '流程描述', width:320, dataIndex:'details'},
			{header: '状态', width:80, dataIndex:'status',renderer:function(v){
				return response.status[v];
			}},
			{header: '备注', width:240, dataIndex:'remark'}
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    sm			: sm,
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
					store.reload(); 
				}
			},'-',{
				text	: '填写单据',
				iconCls	: 'icon-detail',
				handler : function(){
					var rec = sm.getSelected();
					if(rec && rec.get('status') == '1') {
						var url = '/admin/workflow/executor/xxx.html'.replace('xxx', rec.get('id'));
						window.open(url);
					}
				}
			},'-',{
			text	: '删除流程',
			iconCls	: 'icon-delete',
			url     : '/admin/workflow/apply/dodelete.html',
			handler : function(){
					var rs = sm.getSelected();
					if(!rs) {
						Ext.Msg.alert('信息提示','请先选择要废除的流程！');return;
					}
					Ext.Msg.confirm('信息提示', '请确定是否要废除选中的工作流?', function(btn){
						if(btn == 'yes') {
							Ext.Ajax.request({
								url		: '/admin/workflow/apply/dodelete.html',
								params 	: {'id':rs.get('id')},
								success : function(resp, req){
									var data = Ext.decode(resp.responseText);
									if(data.code != 0) {
										Ext.Msg.alert('信息提示', data.msg);
									}
									store.reload(); 
								}
							});
						}
					});
				}
			},'-',{
			text	: '编辑流程',
			iconCls	: 'icon-edit',
			url     : '/admin/workflow/main.html',
			handler : function(){
				var rs = sm.getSelected();
				if(!rs) {
					Ext.Msg.alert('信息提示','请先选择要编辑的工作流！');return;
				}
				var url= '/admin/workflow/id-xxx.html'.replace('xxx', rs.get('id'));
				window.open(url);
			}
			},'-',{
				text	: '单据复制',
				iconCls	: 'icon-add',
				url     : '/admin/workflow/apply/docopy.html',
				handler : function(){
						var rec = sm.getSelected();
						if(!rec) {
							Ext.Msg.alert('信息提示','请先选择要复制的工作流！');
							return;
						}
						Ext.Msg.confirm('信息提示','您是否确认要复制该单据<br />用作开发使用?',function(btn){
							if(btn == 'yes') {
								Ext.Ajax.request({
									url		: '/admin/workflow/apply/docopy.html',
									params 	: {'id':rec.get('id')},
									success : function(resp, req){
										var data = Ext.decode(resp.responseText);
										(data.code == 0)? store.reload():Ext.Msg.alert('信息提示', data.msg);
									}
								});
							}
						});
					}
			},'-','<b>检索资料：</b>','流程名称:',{
				xtype       : 'textfield',
				id	    	: sid.name,
				width	    : 80
			},'状态:',{
				xtype		: 'combo',
				store		: new Ext.data.ArrayStore({
			        fields: ['id','name'],
			        data: main.cv2Array(response.status)
			    }),
				displayField	: 'name',
				valueField		: 'id',
				mode			: 'local',
				triggerAction	: 'all',
				emptyText		: '请选择',
				width			: 80,
				id  			: sid.status
			},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams.name  = Ext.getCmp(sid.name).getValue();
				store.baseParams.status= Ext.getCmp(sid.status).getValue();
				store.reload(); 
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
	return grid;
}();